import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:x_core/x_core.dart';
import 'package:x_project/res/string_res/str_res_en.dart';
import 'package:x_project/res/string_res/str_res_keys.dart';
import 'package:x_project/res/string_res/str_res_zh.dart';

/// Created by XieXin on 2022/8/17.
/// 国际化
/// 使用方式
/// 直接key点tr就行
/// Text('hello'.tr);
///
/// 使用 Get.updateLocale 更改语言
/// Get.updateLocale(const Locale('en', 'US'));
class TranslationService extends Translations {
  static Locale? get locale => Get.deviceLocale;
  static const zhCN = Locale('zh', 'CN');
  static const enUS = Locale('en', 'US');
  static const fallbackLocale = enUS;

  @override
  Map<String, Map<String, String>> get keys => {
        'zh_CN': zhCNRes,
        'en_US': enUSRes,
      };

  ///需要在启动的时候初始化
  static void initNetString() {
    NetException.successStr = SR.success.tr;
    NetException.successNotContentStr = SR.successNotContent.tr;
    NetException.syntaxErrorStr = SR.syntaxError.tr;
    NetException.unauthorizedStr = SR.unauthorized.tr;
    NetException.forbiddenStr = SR.forbidden.tr;
    NetException.notFoundStr = SR.notFound.tr;
    NetException.requestForbidStr = SR.requestForbid.tr;
    NetException.internalServerErrorStr = SR.internalServerError.tr;
    NetException.invalidRequestStr = SR.invalidRequest.tr;
    NetException.serverDownStr = SR.serverDown.tr;
    NetException.nonsupportHttpStr = SR.nonsupportHttp.tr;
    NetException.netExceptionStr = SR.netException.tr;
    NetException.parseExceptionStr = SR.parseException.tr;
    NetException.socketExceptionStr = SR.socketException.tr;
    NetException.httpExceptionStr = SR.httpException.tr;
    NetException.connectTimeoutExceptionStr = SR.connectTimeoutException.tr;
    NetException.requestTimeoutExceptionStr = SR.requestTimeoutException.tr;
    NetException.responseTimeoutExceptionStr = SR.responseTimeoutException.tr;
    NetException.cancelExceptionStr = SR.cancelException.tr;
    NetException.notNetExceptionStr = SR.notNetException.tr;
    NetException.dataExceptionStr = SR.dataException.tr;
    NetException.unknownExceptionStr = SR.unknownException.tr;
  }
}
